# -*- coding: utf-8 -*-
import sys
if sys.getdefaultencoding() != 'utf-8':
    reload(sys)
    sys.setdefaultencoding('utf-8')
import os, inspect
cwd = os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0])
sys.path[0:0] = [os.path.join(cwd, 'resources/lib')]
#print sys.path
try:
    from dmds.addon import plugin, log, message, _ #, menu_show_settings
except:
    import traceback
    traceback.print_exc()
from pprint import pprint

dbg = True
dbglevel = 5

@plugin.route('/')
def index():
    items = [
        {
            'label': 'Run DMDS Player',
            'path': plugin.url_for('run_dmds_player'),
            'is_folder': False,
        },
        {
            'label': _('Check Media Updates'),
            'path': plugin.url_for('check_media_updates'),
            'is_folder': False,
        },
        {
            'label': _('Extract Media Files'),
            'path': plugin.url_for('extract_media_files'),
            'is_folder': False,
        },
        {
            'label': _('Clean Up All Files'),
            'path': plugin.url_for('cleanup_media_files'),
            'is_folder': False,
        },
#        {
#            'label': _('Set Skin Background'),
#            'path': plugin.url_for('set_skin_background'),
#            'is_folder': False,
#        },
        {
            'label': _('Settings'),
            'path': plugin.url_for('show_settings'),
            'is_folder': False,
        },
    ]
    return items

if __name__ == '__main__':
    import traceback
    try:
        plugin.run()
    except Exception, e:
        pprint(str(e))
        plugin.notify(str(e), delay=15000)
        from cStringIO import StringIO
        h = StringIO()
        traceback.print_exc(file=h)
        h.write("\n"+str(inspect.getargvalues(sys.exc_info()[2].tb_frame))+"\n")
        h.write(str(sys.argv)+"\n")
        c = h.getvalue()
        pprint(c)
        log.warning(c)
        message(c)
        raise
    except:
        traceback.print_exc()
        raise
